<?php
function view_toko(){
	view_header_top();
	$id = $_SESSION['logged']['id'];
	$user = getUser($_SESSION['logged']['id']);
	//----------------------------------------------------------------
	$title = "Realita - ".$user['nama'];
	$content = "Realita ".$user['nama'];
	$url = PROFIL_URL."a/".$user['idFB'];
	$image = IMAGE_URL."300x240.gif";	//profpic orangnya / tokonya
	$desc = "Profil orangnya : ".$user['bio'];
	$auth = "RealiTA";
	$qwords = "profil, marketplace, umkm".$user['nama'];
	//----------------------
	echo "<title>$title</title>";
	//<!--META DATA Open Graph-->
	echo "<meta property=\"og:title\" content=\"$title\"/>";
	echo "<meta property=\"og:type\" content=\"$content\"/>";
	echo "<meta property=\"og:url\" content=\"$url\"/>";
	echo "<meta property=\"og:image\" content=\"$image\"/>";
	echo "<meta property=\"og:site_name\" content=\"RealiTA UMKM\"/>";
	echo "<meta property=\"og:description\" content=\"$desc\" />";
	//<!--META DATA FB-->
	echo "<meta property=\"fb:app_id\" content=\"147346958657510\" />";
	//<!--META DATA-->
	echo "<meta name=\"author\" content=\"$auth\" />";
	echo "<meta name=\"keywords\" content=\"$qwords\" />";
	echo "<meta name=\"description\" content=\"$desc\" />";
	echo "<meta name=\"robots\" content=\"ALL\" />";
	echo "<meta charset=\"UTF-8\" />";
	//----------------------------------------------------------------
	view_header_bottom();
?>
<!-- Content -->
	<div class="row">    
		<!-- Main Content Section -->
		<!-- This has been source ordered to come first in the markup (and on small devices) but to be to the right of the nav on larger screens -->
		<div class="large-9 push-3 columns">		  
		  <h3><?php echo $user['nama']; ?></h3>
		  <?php
			  if (isset($_SESSION['message'])) {
					echo "<div class='alert-box warning'>".$_SESSION['message']."<a href='#' class='close'>&times;</a></div>";
					unset($_SESSION['message']);
			}
			?>
		  <hr />
		  <?php
			if (!$user['isToko']){	//belum buka toko
				echo "<h4>Buka Toko sekarang ! </h4>";
				//echo "<a id=\"btn-buka\" href=\"javascript:buka();\" class=\"button success tiny\">Buka</a></h4>";
				?>
				<div class="row" style="display:block" id="isian">
					<form method="post" action="<?php echo TOKO_URL."buka" ?>">
					<input type="hidden" name="index" value="<?php echo $user['idPengguna'] ?>" />
					<input type="hidden" name="idfb" value="<?php echo $user['idFB'] ?>" />
					<div class="large-12 columns">
						<div class="row">
							<div class="large-8 columns">
								<label>Nama Toko</label>
								<input type="text" name="nama-toko" placeholder="Nama toko..." value="" />
							  </div>
						</div>
						<div class="row">
							<div class="large-12 columns">
								<label>Alamat Toko</label>
								<textarea name="alamat-toko" placeholder="alamat lengkap toko..."></textarea>
							  </div>
						</div>
						<div class="row">
							<div class="large-12 columns">
								<label>Deskripsi Toko</label>
								<textarea name="desc-toko" placeholder="deskripsi singkat toko..."></textarea>
							  </div>
						</div>
						<div class="row">
							<div class="large-8 columns">
								<label>Facebook Page</label>
								<div class="row collapse">
									<div class="small-3 large-4 columns">
										<span class="prefix">http://facebook.com/</span>
									</div>
									<div class="small-9 large-8 columns">
										<input name="fb-toko" type="text" placeholder="Alamat page Facebook" value="" />
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="large-12 columns ui-widget">
								<label>Pilih gambar Logo</label>
								<input type="file" name="gambar" />
							</div>
						</div>
						<div class="row">
							<div class="large-12 columns">
								<input class="button" type="submit" value="Buka Toko"/>
							  </div>
						</div>
					</div>
					</form>
				</div>
				<?php
			}else{
			?>
				<a href="<?php echo TOKO_URL."a/".$user['idFB']."/".$user['slug_nama-toko'] ?>"><h4>"<?php echo $user['nama-toko']; ?>"</h4></a>
				<h5><a href="javascript:bkttp('ubah_toko');">Ubah Toko</a></h5>
				<div id="ubah_toko" style="display:none">
					<div class="row" style="display:block" id="isian">
						<form method="post" action="<?php echo TOKO_URL."edit" ?>">
						<input type="hidden" name="index" value="<?php echo $user['idPengguna'] ?>" />
						<input type="hidden" name="idfb" value="<?php echo $user['idFB'] ?>" />
						<div class="large-12 columns">
							<div class="row">
								<div class="large-8 columns">
									<label>Nama Toko</label>
									<input type="text" name="nama-toko" placeholder="Nama toko..." value="<?php echo $user['nama-toko'] ?>" />
								  </div>
							</div>
							<div class="row">
								<div class="large-12 columns">
									<label>Alamat Toko</label>
									<textarea name="alamat-toko" placeholder="alamat lengkap toko..."><?php echo $user['alamat-toko'] ?></textarea>
								  </div>
							</div>
							<div class="row">
								<div class="large-12 columns">
									<label>Deskripsi Toko</label>
									<textarea name="desc-toko" placeholder="deskripsi singkat toko..."><?php echo $user['deskripsi-toko'] ?></textarea>
								  </div>
							</div>
							<div class="row">
								<div class="large-8 columns">
									<label>Facebook Page</label>
									<div class="row collapse">
										<div class="small-3 large-4 columns">
											<span class="prefix">http://facebook.com/</span>
										</div>
										<div class="small-9 large-8 columns">
											<input name="fb-toko" type="text" placeholder="Alamat page Facebook" value="<?php echo $user['fb_page-toko'] ?>" />
										</div>
									</div>
								</div>
							</div>
							<div class="row">
								<div class="large-12 columns ui-widget">
									<label>Pilih gambar Logo</label>
									<input type="file" name="gambar" />
								</div>
							</div>
							<div class="row">
								<div class="large-12 columns">
									<input class="button" type="submit" value="Ubah Toko"/>
								  </div>
							</div>
						</div>
						</form>
					</div>
				</div>
				<h5><a href="javascript:bkttp('tambah_barang');">Tambah Barang</a></h5>
				<div id="tambah_barang" style="display:none">
					<div class="row">
						<div class="large-8 columns">
							<a href="javascript:bkttp('tambah_upload');"><h6>Upload</h6></a>
							<div id="tambah_upload" style="display:none">
								<form class="custom" action="<?php echo TOKO_URL."tambah" ?>" method="post" enctype="multipart/form-data">
								<div class="large-12 columns">
									<fieldset>
										<legend>Unggah file .xls</legend>
										<div class="row">
											<div class="large-12 columns ui-widget">
												<label for="from">Pilih file (*.xls)</label>
												<input id="from" type="file" name="file" />
											</div>
										</div>
										<div class="row">
											<div class="large-12 columns ui-widget">
												<label>Pilih gambar</label>
												<input type="file" name="gambar" />
											</div>
										</div>
										<div class="row">
											<div class="large-12 columns ui-widget">
												<input id="unggah" value="Unggah" name="tambah_upload" type="submit" name="upload" />
											</div>
										</div>
									</fieldset>
								</div>
								</form>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="large-8 columns">
							<a href="javascript:bkttp('tambah_form');"><h6>Form</h6></a>
							<div id="tambah_form" style="display:none">
								<form method="post" action="<?php echo TOKO_URL."tambah" ?>">
								<div class="large-12 columns">
									<div class="row">
										<div class="large-10 columns">
											<label>Nama Barang</label>
											<input type="text" name="nama-barang" placeholder="Nama barang...">
										  </div>
									</div>
									<div class="row">
										<div class="large-4 columns">
											<div class="row collapse">
											  <label>Berat Barang</label>
											  <div class="small-7 columns">
												<input name="berat-barang" type="text" placeholder="1">
											  </div>
											  <div class="small-5 columns">
												<span class="postfix"> gram</span>
											  </div>
											</div>
										</div>
									</div>
									<div class="row">
										<div class="large-5 columns">
											<div class="row collapse">
											  <label>Harga Barang</label>
											  <div class="small-3 columns">
												<span class="prefix">Rp. </span>
											  </div>
											  <div class="small-9 columns">
												<input name="harga-barang" type="text" placeholder="1">
											  </div>
											</div>
										</div>
									</div>
									<div class="row">
										<div class="large-3 columns">
											<label>Pre Order</label>
											<select name="pre-order">
												<option value="0">Tidak</option>
												<option value="1">Ya</option>
											</select>
										 </div>
									</div>
									<br />
									<div class="row">
										<div class="large-6 columns">
											<label>Kategori</label>
											<select name="kategori">
												<option value="0">Lain-lain</option>
												<option value="1">Fashion</option>
												<option value="2">Komputer-Laptop</option>
												<option value="3">Handphone-Tablet</option>
												<option value="4">Elektronik Lain</option>
												<option value="5">Kesehatan &amp; Kecantikan</option>
												<option value="6">Perlengkapan Rumah</option>
												<option value="7">Perlengkapan Kantor</option>
												<option value="8">Perlengkapan Lain</option>
												<option value="9">Aksesoris</option>
												<option value="10">Souvenir</option>
												<option value="11">Koleksi</option>
												<option value="12">Kesenian &amp; Kerajinan Tangan</option>
												<option value="13">Hobi &amp; Olahraga</option>
												<option value="14">Kebun &amp; Taman</option>
												<option value="15">Makanan</option>
											</select>
										 </div>
									</div>
									<br />
									<div class="row">
										<div class="large-12 columns">
											<label>Deskripsi Barang</label>
											<textarea name="desc-barang" placeholder="deskripsi singkat barang..."></textarea>
										  </div>
									</div>
									<div class="row">
										<div class="large-12 columns">
											<label>Tag</label>
											<textarea name="tag-barang" placeholder="pisahkan dengan tanda koma ','"></textarea>
										  </div>
									</div>
									<div class="row">
										<div class="large-12 columns ui-widget">
											<label>Tambah Gambar</label>
											<input type="file" name="gambar" />
										</div>
									</div>
									<div class="row">
										<div class="large-12 columns">
											<input class="button" name="tambah_form" type="submit" value="Tambah"/>
										  </div>
									</div>
								</div>
								</form>
							</div>
						</div>
					</div>
				</div>
				<h5><a href="javascript:bkttp('ubah_barang');">Ubah Barang</a></h5>
				<div id="ubah_barang" style="display:none">
				<?php
					 $barangs = getListBarang($user['idPengguna']);
					 if (count($barangs)>0){
						 echo "<ul>";
						 foreach ($barangs as $barang){
							 echo "<li><a href=\"".PROFIL_URL."edit/barang/".$barang['idBarang']."\">".$barang['nama']."</a></li>";
						 }
						 echo "</ul>";
					}else{
						//kosong
						echo "<h3>Belum ada barang</h3>";
					}
				?>
				</div>
			<?php
			}
		  ?>
		</div>
		<!-- Nav Sidebar -->
		<!-- This is source ordered to be pulled to the left on larger screens -->
		<?php view_tab($user); ?>
	  </div>
	  <script type="text/javascript">
		function buka(){
			$('#isian').show('fast',function(){
				//$('btn-buka').hide();
			});
		};
	  </script>
    <!-- End Content -->
<?php
	view_footer();
}

function edit_barang($idbarang){
	view_header_top();
	$id = $_SESSION['logged']['id'];
	$user = getUser($_SESSION['logged']['id']);
	//----------------------------------------------------------------
	$title = "Realita - ".$user['nama'];
	$content = "Realita ".$user['nama'];
	$url = PROFIL_URL."a/".$user['idFB'];
	$image = IMAGE_URL."300x240.gif";	//profpic orangnya / tokonya
	$desc = "Profil orangnya : ".$user['bio'];
	$auth = "RealiTA";
	$qwords = "profil, marketplace, umkm".$user['nama'];
	//----------------------
	echo "<title>$title</title>";
	//<!--META DATA Open Graph-->
	echo "<meta property=\"og:title\" content=\"$title\"/>";
	echo "<meta property=\"og:type\" content=\"$content\"/>";
	echo "<meta property=\"og:url\" content=\"$url\"/>";
	echo "<meta property=\"og:image\" content=\"$image\"/>";
	echo "<meta property=\"og:site_name\" content=\"RealiTA UMKM\"/>";
	echo "<meta property=\"og:description\" content=\"$desc\" />";
	//<!--META DATA FB-->
	echo "<meta property=\"fb:app_id\" content=\"147346958657510\" />";
	//<!--META DATA-->
	echo "<meta name=\"author\" content=\"$auth\" />";
	echo "<meta name=\"keywords\" content=\"$qwords\" />";
	echo "<meta name=\"description\" content=\"$desc\" />";
	echo "<meta name=\"robots\" content=\"ALL\" />";
	echo "<meta charset=\"UTF-8\" />";
	//----------------------------------------------------------------
	view_header_bottom();
	$barang = getBarang($idbarang);
?>
<!-- Content -->
	<div class="row">    
		<!-- Main Content Section -->
		<!-- This has been source ordered to come first in the markup (and on small devices) but to be to the right of the nav on larger screens -->
		<div class="large-9 push-3 columns">		  
		  <h3><?php echo $user['nama-toko']; ?></h3>
		  <?php
			  if (isset($_SESSION['message'])) {
					echo "<div class='alert-box warning'>".$_SESSION['message']."<a href='#' class='close'>&times;</a></div>";
					unset($_SESSION['message']);
			}
			?>
		  <hr />
		  <h4>Edit Barang : <?php echo $barang['nama'] ?></h4>
		  <h5><a href="<?php echo PROFIL_URL ?>">[Hapus]</a></h5>
		  <form method="post" action="<?php echo BARANG_URL."edit" ?>">
			<input type="hidden" name="index" value="<?php echo $user['idPengguna'] ?>" />
			<input type="hidden" name="idbarang" value="<?php echo $barang['idBarang'] ?>" />
			<div class="large-12 columns">
				<div class="row">
					<div class="large-6 columns">
						<label>Nama Barang</label>
						<input type="text" name="nama-barang" placeholder="Nama barang..." value="<?php echo $barang['nama'] ?>" />
					  </div>
				</div>
				<div class="row">
					<div class="large-3 columns">
						<div class="row collapse">
						  <label>Berat Barang</label>
						  <div class="small-7 columns">
							<input name="berat-barang" type="text" placeholder="1" value="<?php echo $barang['berat'] ?>" />
						  </div>
						  <div class="small-5 columns">
							<span class="postfix"> gram</span>
						  </div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="large-3 columns">
						<div class="row collapse">
						  <label>Harga Barang</label>
						  <div class="small-3 columns">
							<span class="prefix">Rp. </span>
						  </div>
						  <div class="small-9 columns">
							<input name="harga-barang" type="text" placeholder="1" value="<?php echo $barang['harga'] ?>" />
						  </div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="large-2 columns">
						<label>Pre Order</label>
						<select name="pre-order">
							<option value="0" <?php if($barang['preorder']==0) echo "selected"; ?>>Tidak</option>
							<option value="1" <?php if($barang['preorder']==1) echo "selected"; ?>>Ya</option>
						</select>
					 </div>
				</div>
				<br />
				<div class="row">
					<div class="large-5 columns">
						<label>Kategori</label>
						<select name="kategori">
							<option value="0" <?php if($barang['kategori']==0) echo "selected"; ?>>Lain-lain</option>
							<option value="1" <?php if($barang['kategori']==1) echo "selected"; ?>>Fashion</option>
							<option value="2" <?php if($barang['kategori']==2) echo "selected"; ?>>Komputer-Laptop</option>
							<option value="3" <?php if($barang['kategori']==3) echo "selected"; ?>>Handphone-Tablet</option>
							<option value="4" <?php if($barang['kategori']==4) echo "selected"; ?>>Elektronik Lain</option>
							<option value="5" <?php if($barang['kategori']==5) echo "selected"; ?>>Kesehatan &amp; Kecantikan</option>
							<option value="6" <?php if($barang['kategori']==6) echo "selected"; ?>>Perlengkapan Rumah</option>
							<option value="7" <?php if($barang['kategori']==7) echo "selected"; ?>>Perlengkapan Kantor</option>
							<option value="8" <?php if($barang['kategori']==8) echo "selected"; ?>>Perlengkapan Lain</option>
							<option value="9" <?php if($barang['kategori']==9) echo "selected"; ?>>Aksesoris</option>
							<option value="10" <?php if($barang['kategori']==10) echo "selected"; ?>>Souvenir</option>
							<option value="11" <?php if($barang['kategori']==11) echo "selected"; ?>>Koleksi</option>
							<option value="12" <?php if($barang['kategori']==12) echo "selected"; ?>>Kesenian &amp; Kerajinan Tangan</option>
							<option value="13" <?php if($barang['kategori']==13) echo "selected"; ?>>Hobi &amp; Olahraga</option>
							<option value="14" <?php if($barang['kategori']==14) echo "selected"; ?>>Kebun &amp; Taman</option>
							<option value="15" <?php if($barang['kategori']==15) echo "selected"; ?>>Makanan</option>
						</select>
					 </div>
				</div>
				<br />
				<div class="row">
					<div class="large-12 columns">
						<label>Deskripsi Barang</label>
						<textarea name="desc-barang" placeholder="deskripsi singkat barang..."><?php echo $barang['deskripsi'] ?></textarea>
					  </div>
				</div>
				<div class="row">
					<div class="large-12 columns">
						<label>Tag</label>
						<textarea name="tag-barang" placeholder="pisahkan dengan tanda koma ','"><?php echo $barang['keywords'] ?></textarea>
					  </div>
				</div>
				<div class="row">
					<div class="large-12 columns ui-widget">
						<label>Tambah Gambar</label>
						<input type="file" name="gambar" />
					</div>
				</div>
				<div class="row">
					<div class="large-12 columns">
						<input class="button" name="ubah" type="submit" value="Ubah"/>
					  </div>
				</div>
			</div>
		  </form>
		</div>
		<!-- Nav Sidebar -->
		<!-- This is source ordered to be pulled to the left on larger screens -->
		<?php view_tab($user); ?>
	  </div>
    <!-- End Content -->
<?php
	view_footer();
}
